#include <bits/stdc++.h>

using namespace std;
typedef long long ll;
const int MAXN = 2e5 + 5;
int n,a[MAXN];
ll ans;
int vis[MAXN];

void dfs(int pos)
{
    if (pos == n + 1){
        int p1 = 0,p2 = 0;
        ll cnt = 0;
        for (int i=1;i <= n;i++){
            if (vis[i] == 1){
                if (p1 && a[i] == a[p1]){
                    cnt += a[i];
                }
                p1 = i;
            }else{
                if (p2 && a[i] == a[p2]){
                    cnt += a[i];
                }
                p2 = i;
            }
        }
        ans = max(ans,cnt);
        return ;
    }
    vis[pos] = 1;
    dfs(pos+1);
    vis[pos] = 2;
    dfs(pos+1);
    vis[pos] = 0;
}

int main()
{
    freopen("color.in","r",stdin);
    freopen("color.out","w",stdout);
    int t;
    scanf("%d",&t);
    while (t--){
        scanf("%d",&n);
        for (int i=1;i <= n;i++){
            scanf("%d",&a[i]);
        }
        ans = 0;
        dfs(1);
        printf("%lld\n",ans);
    }

    return 0;
}
